package Core;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Logger;

public class DB {
	Logger log = Logger.getAnonymousLogger();	
	Settings settings = new Settings();
	Connection conn = null;
	
	public DB() {
	
	String port = settings.ZeusSettings.getProperty("dbport","3306");
	String url = "jdbc:mysql://localhost:"+port+"/";
	String dbName = settings.ZeusSettings.getProperty("dbname","zeus");
	String driver = "com.mysql.jdbc.Driver";
	String userName = settings.ZeusSettings.getProperty("dbuser","zeus"); 
	String password = settings.ZeusSettings.getProperty("dbpwd","zeus");
	
	try {
	Class.forName(driver); //.newInstance();
	conn = DriverManager.getConnection(url+dbName,userName,password);
	log.info("Connected to the database");
	
	} catch (Exception e) {
			e.printStackTrace();
	}
	}
	
	public Connection getCon() {
		return conn;
	}
	public void close() {
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			log.info(e.getMessage());
		}
		log.info("Closing DB connection");
	}
}
